#ifndef __FIFO_H__
#define __FIFO_H__

#include "BasicInclude.h"

struct fifo {
	unsigned int mask;
	unsigned int in;
	unsigned int out;

	uint8_t *data;
};

static inline unsigned int fifo_cnt(struct fifo *fifo)
{
	return fifo->in - fifo->out;
}

static inline unsigned int fifo_space(struct fifo *fifo)
{
	return (fifo->mask + 1) - (fifo->in - fifo->out);
}

static inline void fifo_reset(struct fifo *fifo)
{
	fifo->in = fifo->out = 0;
}

unsigned int fifo_in(struct fifo *fifo, const uint8_t *src, unsigned int cnt);
unsigned int fifo_in_for_dma(struct fifo *fifo, const uint8_t *src, unsigned int cnt);
unsigned int fifo_out(struct fifo *fifo, uint8_t *des, unsigned int cnt);


struct fifo *fifo_alloc(unsigned int size);
void fifo_free(struct fifo *fifo);

void fifo_init(struct fifo *fifo, uint8_t *data, unsigned int size);

#endif

